package per.hnvcam.searchext.text.impl;

import org.springframework.stereotype.Service;
import per.hnvcam.searchext.Constants;
import per.hnvcam.searchext.text.CommonWords;

import java.util.HashSet;
import java.util.ResourceBundle;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: violon
 * Date: 5/3/11
 * Time: 3:31 PM
 * To change this template use File | Settings | File Templates.
 */
@Service("CommonWords")
public class CommonWordsImpl implements CommonWords {

    private ResourceBundle resourceBundle;

    private Set<String> commonWords;

    public CommonWordsImpl() {
        resourceBundle = ResourceBundle.getBundle("commonWords");
        commonWords = new HashSet<String>();
        getWords();
    }

    public boolean contains(String word) {
        return commonWords.contains(word);
    }

    private void getWords() {
        String value = resourceBundle.getString(Constants.VALUE);
        if (value != null) {
            String [] words = value.split(" ");
            for (String word : words) {
                commonWords.add(word);
            }
        }
    }
}
